function isMobile(){
    return (
        (navigator.userAgent.match(/Android/i)) ||
		(navigator.userAgent.match(/webOS/i)) ||
		(navigator.userAgent.match(/iPhone/i)) ||
		(navigator.userAgent.match(/iPod/i)) ||
		(navigator.userAgent.match(/iPad/i)) ||
		(navigator.userAgent.match(/BlackBerry/))
    );
}
function scrollBackground() {
	var scrollTop = $(this).scrollTop();
	//console.log(scrollTop);
	$(".index-txt").css({
		"opacity": 1 - (scrollTop / 500)
	});
	$(".index-banner").css({
		"background-position-y": -scrollTop / 12 + 'px'
	});
	$(".index-banner2").css("background-position-y", scrollTop / 20 + 'px');
	$(".p3-banner").css("background-position-y", scrollTop / 8 + 'px');
	$(".p4-banner").css("background-position-y", scrollTop / 13 + 'px');

	var fz=
	$(".p2-title span").removeClass('tit-spec').css({
		opacity: (scrollTop / 100),
		'font-size': ((16 + scrollTop / 12)>50?50:(16 + scrollTop / 12) )+ "px",
		color: '#fff'
	});
	$(".p2-title p").css({
		opacity: (scrollTop / 100),
		'font-size': (12 + scrollTop / 40) + "px",
		color: '#fff'
	});
	
	if((scrollTop / 20) < 3.5) {
		$(".p2-title p").css({
			color: '#464646',
			'opacity': '1',
			fontSize: '18px'
		});
		$(".p2-title span").addClass('tit-spec').css({
			color: '#464646',
			'opacity': '1',
			fontSize: '40px'
		});
	}

	function scales(t) {
		var scaleNum = scrollTop / t > 1 ? 1 : scrollTop / t;
		trans_css = {
			transform: "scale(" + scaleNum + ")"
		};
		return trans_css;
	}

	$(".p3-title").css(scales(1250));
	$(".p4-title").css(scales(2150));

}

function scrollPos() {
	var scrollTop = $(this).scrollTop(),
		winH = $(window).height(),
		curId = '';

	$(".con-page").each(function() {
		var $that = $(this),
			itemTop = $that.offset().top;
		(scrollTop > itemTop - (winH / 2.5)) && (curId = $that.attr('id'));
	})

	var $curLink = $(".menu-box-info").find('.active');
	if(curId && $curLink.data('href') != curId) {
		$curLink.removeClass('active');
		$(".menu-box-info li").find("[data-href=" + curId + "]").addClass('active');
	}
}

//遮罩层
var shadow = {
	getDirection: function($target, e) {
		var w = $target.width(),
			h = $target.height(),
			x = (event.pageX - $target.offset().left - (w / 2)) * (w > h ? (h / w) : 1),
			y = (event.pageY - $target.offset().top - (h / 2)) * (h > w ? (w / h) : 1);
		this.direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
		return this.direction;
	},
	create: function($target, e) {
		this.getDirection($target, e);

		var left, bottom, finalState,
			direction = this.direction;
		//console.log(direction);
		switch(direction) {
			case 0:
				//from top
				finalState = {
					left: 0,
					bottom: '100%'
				};
				break;
			case 1:
				//from right
				finalState = {
					left: '100%',
					bottom: 0
				};
				break;
			case 2:
				//from bottom
				finalState = {
					left: 0,
					bottom: '-100%'
				};
				break;
			case 3:
				//from left
				finalState = {
					left: '-100%',
					bottom: 0
				};
				break;
		};

		//遮罩移入操作
		$overlay = $target.find('.tips');
		$overlay.css(finalState);
		$overlay.stop().animate({
			left: 0,
			bottom: 0
		}, 200);
	},
	remove: function($target, e) {
		this.getDirection($target, e);

		var left, bottom, finalState,
			direction = this.direction;
		switch(direction) {
			case 0: //to top
				finalState = {
					bottom: '100%',
					left: 0
				};
				break;
			case 1: //to right
				finalState = {
					bottom: 0,
					left: '100%'
				};
				break;
			case 2: //to bottom
				finalState = {
					bottom: '-100%',
					left: 0
				};
				break;
			case 3: //to left
				finalState = {
					bottom: 0,
					left: '-100%'
				};
				break;
		}
		//遮罩移出操作
		$overlay = $target.find('.tips');
		$overlay.stop().animate(finalState, 200);

	}
}
$(window).scroll(function() {
	(!isMobile()) && (scrollBackground());
	scrollPos();

});

/*导航跳转*/
var $menu = $('.menu-box-info li a');
$menu.on('click', function() {
	var $pos_ele = $(this).data('href');
	var pos_top = $("#" + $pos_ele).offset().top - 195;
	$("body,html").stop().animate({
		scrollTop: pos_top
	}, 500)
})

/*小屏幕菜单*/
/*$('.menu-button').on('click',function(){
	$(".header-bar,.bing-pages").toggleClass('navOpened');
})*/
var $meu_btn=$(".menu-button");
$meu_btn.on('click',function(e){
	e.stopPropagation();
	$(".header-bar,.bing-pages").toggleClass('navOpened');
})
$(document).on('click',function(e){
	$(".header-bar,.bing-pages").removeClass('navOpened');
})

//遮罩跟随鼠标移动
$(".adaptImg").hover(function() {
	shadow.create($(this), event);
}, function() {
	shadow.remove($(this), event);
})
/*侧栏客服*/
var $close = $(".close-btn"),
	$side_title = $('.side_title'),
	$con = $('.side_center'),
	$kf_box = $(".right-contact");
$close.on('click', function() {
	$side_title.toggleClass('pull-back');
	$kf_box.toggleClass('hideclass');
	$con.slideToggle('fast');
});

var myVali = {
	notNull: function(_this, str) {
		if(!(_this.val().trim())) {
			return this.toast(_this, str);
		} else {
			return true;
		}
	},
	phone: function(_this, str) {
		var reg = /(^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$)|(^1[34578]\d{9}$)/;
		if(!reg.test(_this.val())) {
			return this.toast(_this, str);
		} else {
			return true;
		}
	},
	toast: function(_this, str) {
		//layer.msg(str, function() {});
		layer.msg(str,{
			icon: 5,
			anim: 6
		});
		_this.focus();
		return false;
	}
}